package com.czh.system.controller.auth;

import com.czh.common.domain.AjaxRes;
import com.czh.framework.security.web.service.AuthService;
import com.czh.service.entity.dto.LoginUserDto;
import com.czh.service.entity.dto.MailLoginDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("auth")
public class AuthController {
    @Autowired
    AuthService authService;

    @PostMapping("login")
    public AjaxRes login(@RequestBody LoginUserDto loginUserDto) {
        String token = authService.login(loginUserDto);

        AjaxRes success = AjaxRes.success();
        success.put(AjaxRes.KEY_TOKEN,token);
        return success;
    }

    @PostMapping("sendMail")
    public AjaxRes sendMail(String mail) {
        AjaxRes ajaxRes = authService.mailLogin(mail);
        return ajaxRes;
    }

    @PostMapping("mailLogin")
    public AjaxRes mailLogin(@RequestBody MailLoginDto mailLoginDto) {
        return authService.authenticateMailCode(mailLoginDto);
    }

}
